public class test02 {
    //KMP算法：解决重复子串问题
    public boolean repeatedSubstringPattern(String s) {
        int j = 0;
        int[] next = new int[s.length()];
        next[0] = 0;
        for(int i = 1;i<s.length();i++){
            while(j>0 && s.charAt(i)!=s.charAt(j)){
                j = next[j-1];
            }
            if(s.charAt(i)==s.charAt(j)){
                j++;
            }
            next[i] = j;
        }
        int len = s.length();
        if(next[len-1]>0 && len%(len-next[len-1])==0){
            return true;
        }
        return false;
    }
}
